package cn.edu.hqu.cst.android.cxy.test5;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {
    public static int MODE=MODE_PRIVATE;
    public static final String PREFERENCE_NAME="SaveSetting";
    Button btnLogin;
    EditText etAccount,etPassword;
    SharedPreferences sharedPreferences;
    SharedPreferences.Editor sharedPreferencesEditor;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btnLogin=findViewById(R.id.btn_login);
        etAccount=findViewById(R.id.account_input);
        etPassword=findViewById(R.id.password_input);
        btnLogin.setOnClickListener(this::onClick);
        sharedPreferences = getSharedPreferences(PREFERENCE_NAME,MODE);
        sharedPreferencesEditor=sharedPreferences.edit();
        etAccount.setText(sharedPreferences.getString("account",null).toString());
        etPassword.setText(sharedPreferences.getString("password",null).toString());
    }
    public void onClick(View v) {
        switch(v.getId()){
            case R.id.btn_login:
                sharedPreferencesEditor.putString("account",etAccount.getText().toString());
                sharedPreferencesEditor.putString("password",etPassword.getText().toString());
                sharedPreferencesEditor.apply();
                Intent i1 = new Intent(MainActivity.this , UC1.class);
                startActivity(i1);
                break;
        }
    }
}